@brief Main controller class for executing the gamma-corrected alpha-blending pipeline.
@details
This class performs an end-to-end pipeline:
- Reads configuration values (input image path, blending side, physical setup, gamma).
- Loads a PNG image (ensuring BGRA so alpha can be modified safely).
- Computes the overlap width in pixels based on the physical projector setup.
- Builds an alpha mask curve (linear ramp) for the overlap region.
- Applies gamma correction to the mask curve.
- Multiplies the image alpha channel by the mask in the overlap region.
- Saves a new PNG with adjusted transparency.
| main_alpha_blender.MainAlphaBlender.run |
( |
| self | ) |
|
@brief Executes the full alpha blending process (gamma corrected).
@details
steps:
1) Load configuration parameters:
- image_name: input image file (ideally PNG with alpha)
- side: "left" or "right" indicating which projector image this is
- proj_width_phys: physical width of one projected image
- dist_phys: physical distance between projector centers (or image origins depending on setup)
- gamma: projector gamma value (> 0)
2) Load image using OpenCV:
- cv2.IMREAD_UNCHANGED preserves alpha if present.
- If the image is BGR (3 channels), it is converted to BGRA (4 channels)
so we can write an alpha mask safely.
3) Compute overlap ratio and overlap width (pixels):
- overlap_ratio = 1 - (dist_phys / proj_width_phys)
Example:
dist_phys == proj_width_phys -> overlap_ratio = 0 (no overlap)
dist_phys < proj_width_phys -> overlap_ratio > 0 (overlap exists)
- overlap_pixels = int(width * overlap_ratio)
4) Generate a base linear ramp across the overlap region:
- linear_ramp is always 0 → 1 across overlap_pixels.
- For the left image: fade out (1 → 0) in the overlap.
- For the right image: fade in (0 → 1) in the overlap.
5) Gamma correction:
- Projector brightness response is non-linear.
- We compensate by applying:
mask_curve = base_curve^(1/gamma)
- This helps produce a visually smoother blend once projected.
6) Apply the mask to the alpha channel:
- Convert alpha to float in [0, 1].
- Expand mask_curve vertically to match image height.
- Multiply only the overlap region of alpha.
7) Save output image:
- Writes output_left.png or output_right.png depending on side.
Error / early-exit conditions:
- If the input image cannot be loaded, the process stops.
- If overlap_ratio <= 0, there is no overlap (or invalid physical config), so it stops.
- If side is not "left" or "right", it stops.
@return This returns None.
@see config_reader.py